﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PatientsManagement.Database;

namespace PatientsManagement.DoctorWindow
{
    public partial class AddVisit : Form
    {
        int patientID,doctorID,visitID;
        public AddVisit(int patientID,int doctorID,string patientName)
        {
            InitializeComponent();
            visitDate.MaxDate = DateTime.Now;
            name.Text = patientName;
            this.patientID = patientID;
            this.doctorID = doctorID;
            FillCombo();
        }

        public AddVisit(int patientID, int doctorID, int visitID, string patientName)
        {
            InitializeComponent();
            FillCombo();
            visitDate.MaxDate = DateTime.Now;
            name.Text = patientName;
            this.patientID = patientID;
            this.doctorID = doctorID;
            this.visitID = visitID;
            diagnosisName.SelectedItem = VisitsData.GetDiagnosisName(visitID);
            visitDate.Value = VisitsData.GetVisitDate(visitID);
            if (VisitsData.PrescriptionExists(visitID))
            {
                prescriptionNumber.Value = int.Parse(VisitsData.PrescriptionNumber(visitID));
            }
            else
                prescriptionAdd.Checked = true;

            add.Text = "Zapisz";
        }

        private void FillCombo()
        {
            List<string> diagnosisNames = VisitsData.DiagnosisNames();
            foreach (string diagnosis in diagnosisNames)
            {
                diagnosisName.Items.Add(diagnosis);
            }
            diagnosisName.SelectedIndex = 0;
        }

        internal void AddToDatabase()
        {
            VisitsData.AddVisit(patientID, doctorID, diagnosisName.Text, visitDate.Value, prescriptionNumber.Value.ToString(), prescriptionAdd.Checked);
        }

        internal void SaveChangesToDatabase()
        {
            VisitsData.SaveChanges(visitID, diagnosisName.Text, visitDate.Value, prescriptionAdd.Checked, prescriptionNumber.Value.ToString());
        }
    }
}
